<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/session.jsp"%>
<c:set var="deptId" value="${param.deptId}" />
<c:set var="deptParentId" value="${param.deptParentId}" />
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <title>staff</title>
    <link rel="stylesheet" href="${ctx}/css/xtable.css"/>
    <script type="text/javascript" src="${ctx}/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/js/validator.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/UserService.js"></script>
</head>
<body>
<img src="${ctx}/images/common/button_insert.jpg" title="添加员工" style="cursor:pointer" onclick="insertStaff()"/>
<img src="${ctx}/images/common/button_back.jpg" title="返回" style="cursor:pointer" onclick="location='${ctx}/dept/dept_list.jsp?deptId=${deptId}&deptParentId=${deptParentId}'"/>
<SCRIPT LANGUAGE="JavaScript" type="">
    var staffThead = new Array(
            new XThead("照片"),
            new XThead("姓名"),
            new XThead("信息部"),
            new XThead("手机号"),
            new XThead("联系人"),
            new XThead("状态"),
            new XThead("入职时间"),
            new XThead("操作")
    );

    var staffXTable = new XTable("staff", staffThead, true);

    staffXTable.XTbodyArray = function (model) {
        var array = new Array(
                new XTbody("staff", "<img width=50 height=50 src='${ctx}" + model.staffPhoto + "' onerror='loadDefaultPhoto(this)' />", null, null, null, "center"),
                new XTbody("staff", model.user.userName, null, null, null, "center"),
                new XTbody("staff", model.dept.deptName, null, null, null, "center"),
                new XTbody("staff", model.user.userMobile, null, null, null, "center"),
                new XTbody("staff", model.staffType == 1 ? "是" : "否", null, null, null, "center"),
                new XTbody("staff", model.staffState == 0 ? "试用" : model.staffState == 1 ? "在职" : model.staffState == 2 ? "离职" : "", null, null, null, "center"),
                new XTbody("staff", new Date(model.staffEntryDate).Format("yyyy/MM/dd"), null, null, null, "center"),
                new XTbody("staff", "<a href='${ctx}/user/staff_manage.jsp?deptId=${deptId}&deptParentId=${deptParentId}&staffId=" + model.staffId + "'>【编辑员工】</a>" +
                        "<a href='${ctx}/staff/staff_child_list.jsp?staffId=" + model.staffId + "'>【授权】</a>",
                        null, null, null, "center")
        );

        return array;
    }
    staffXTable.getXList = function (page){
        var staff = new Staff();
        staff.deptId = "${deptId}";
        UserService.selectStaffList(staff, function(list){staffXTable.addTable(list);});
    }
</SCRIPT>
</body>
</html>
<script type="text/javascript">
    staffXTable.goPage(1);
    function loadDefaultPhoto(obj) {
        obj.onerror=null;
        obj.src="${ctx}/images/head.png";
    }
    function insertStaff() {
        location = "${ctx}/user/staff_manage.jsp?deptId=${deptId}&deptParentId=${deptParentId}";
    }
</script>